<?php
class OurMenu extends CApplicationComponent
{
    public function getAjaxMenu(){
        $treedata = array();
        $model = new Content;
        $children = $model->getHierarchy();
        $treedata=array();
        foreach($children as $child){
            //$options=array('href'=>Yii::app()->createUrl('content/edit',array('id'=>$child['id'])),'id'=>'node-'.$child['id'],'class'=>'treenode');
            //$options=array('onclick'=>'open_frame("'.Yii::app()->createUrl('content/edit',array('id'=>$child['id'])).'")','id'=>'node-'.$child['id'],'class'=>'treenode','style'=>'cursor:pointer;');
            $options=array('href'=>'/content/edit/'.$child['id'],'id'=>'node-'.$child['id'],'class'=>'treenode');
            $nodeText = CHtml::openTag('a', $options);
            $nodeText.= $child['text'];
            $nodeText.= CHtml::closeTag('a')."\n";
            $child['text'] = $nodeText;
            $treedata[]=$child;
        }
        return str_replace(
            '"hasChildren":"0"',
            '"hasChildren":false',
            CTreeView::saveDataAsJson($treedata)
        );

    }
    public function init(){
        parent::init();
    }
}